#include <JXQCore/JMessage>
#include <JXQCore/JString>
#include <JXQCore/JThread>
#include <JXQCore/JDebug>

using namespace JXQ;

class A : public JThread
{
    J_MESSAGE(message, const JString&, int)

protected:
	void run() override
	{
		for(int i=0; i<5; i++)
		{
            message.send("hello", i);
			msleep(500);
		}
	}
};

class B
{
public:
    virtual J_SLOT slot1(const JString &str, int i)
	{
        jDebug() << "B::slot1" << this << str << i;
	}
};

class C : public B
{
public:
    J_SLOT slot1(const JString &str, int i) override
    {
        jDebug() << "C::slot1" << this << str << i;
    }
};

J_SLOT slot2(const JString &str, int i)
{
    jDebug() << "global slot2" << str << i;
}

int main(int argc, char *argv[])
{
	J_UNUSED(argc);
	J_UNUSED(argv);

	A a;
    B *b = new C;

    a.message.subscribe(b, &B::slot1);
	a.message.subscribe(slot2);
    a.message.subscribe([](const JString &str, int i){
        jDebug() << "lambda slot3" << str << i;
	});

	a.finished.subscribe([](){
		jDebug() << "JThread: finished";
	});
	a.start();
	jDebug() << "wait???";
	a.wait();

	return 0;
}
